INSTALL_PATH=~/soft
password=xieqihui
mkdir -p ${INSTALL_PATH}
cd ${INSTALL_PATH}

#判断是否存在，不存在则去下载
if [ ! -d "metricbeat" ]; then
    wget https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.12.0-linux-x86_64.tar.gz
    tar -xzf metricbeat-7.12.0-linux-x86_64.tar.gz
    mv metricbeat-7.12.0-linux-x86_64 metricbeat
    rm metricbeat-7.12.0-linux-x86_64.tar.gz
fi

cd metricbeat

cp metricbeat.yml metricbeat.yml.bak
sed -i '101s/\#//' metricbeat.yml
sed -i '102s/\#//' metricbeat.yml
sed -i '102s/changeme/elastic/' metricbeat.yml
echo "metricbeat.yml 配置完成"

sed '8s/\#//' modules.d/elasticsearch-xpack.yml.disabled| sed '8s/\"user\"/\"elastic\"/g' |sed '9s/\#//' |sed '9s/secret/elastic/' | sed '7c \ \ hosts: ["http://172.17.0.4:9200", "172.17.0.5:9200"]'> tmp.yml
mv tmp.yml modules.d/elasticsearch-xpack.yml
echo "elasticsearch-xpack.yml配置完成"

sed '10s/\#//' modules.d/elasticsearch.yml.disabled| sed '10s/\"user\"/\"elastic\"/g'|sed '11s/\#//' |sed '11s/secret/elastic/'| sed '7c \ \ hosts: ["http://172.17.0.4:9200", "172.17.0.5:9200"]' > tmp.yml
mv tmp.yml modules.d/elasticsearch.yml
echo "elasticsearch.yml 配置完成"

sed '9s/\#//' modules.d/kibana-xpack.yml.disabled| sed '9s/\"user\"/\"elastic\"/g'|sed '10s/\#//' |sed '10s/secret/elastic/' > tmp.yml
mv tmp.yml modules.d/kibana-xpack.yml

echo "kibana-xpack.yml 配置完成"

# 启用监测es和kibana模块
./metricbeat modules enable elasticsearch-xpack
./metricbeat modules enable kibana-xpack